//
//  LLDegegateView.m
//  LoveLove
//
//  Created by leiyifan on 2019/6/25.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLDegegateView.h"
#import <YYText.h>

@implementation LLDegegateView

-(UIButton *)gouBtn{
    if (!_gouBtn) {
        _gouBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_gouBtn setImage:[UIImage imageNamed:@"gou"] forState:UIControlStateNormal];
        [_gouBtn setImage:[UIImage imageNamed:@"gouzhong"] forState:UIControlStateSelected];
        _gouBtn.selected = YES;
        [_gouBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _gouBtn;
}

-(YYLabel *)content{
    if (!_content) {
        _content = [YYLabel new];
        _content.textColor = [UIColor blueColor];
        YYTextDecoration *decoration =[YYTextDecoration decorationWithStyle:YYTextLineStyleSingle
                                        width:@(1)
                                        color:[UIColor blueColor]];
      NSMutableAttributedString *text111 = [[NSMutableAttributedString alloc]initWithString:@"已阅读用户协议和隐私政策"];
//        NSString *text =@"已阅读用户协议和隐私政策";
        [text111 yy_setTextHighlightRange:NSMakeRange(3, 4) color:[UIColor blueColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            NSLog(@"用户协议");
            if (self.clickBlock) {
                self.clickBlock(1,NO);
            }
        }];
        [text111 yy_setTextHighlightRange:NSMakeRange(8, 4) color:[UIColor blueColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            NSLog(@"隐私");
            if (self.clickBlock) {
                self.clickBlock(2,NO);
            }
        }];
    
    [text111 yy_setTextUnderline:decoration range:NSMakeRange(3, 4)];
    [text111 yy_setTextUnderline:decoration range:NSMakeRange(8, 4)];
        _content.attributedText = text111;
        _content.textColor = [UIColor blueColor];
       
    }
    return _content;
}
-(void)click:(UIButton *)button{
    button.selected = !button.selected;
    if (self.clickBlock) {
        self.clickBlock(3, button.selected);
    }
}
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.gouBtn];
         [self addSubview:self.content];
        
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self.gouBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_centerX).with.offset(-50);
        make.top.equalTo(self.mas_top);
        make.size.mas_equalTo(20);
    }];
    
    [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.gouBtn.mas_right).with.offset(10);
        make.centerY.equalTo(self.gouBtn.mas_centerY);
    }];
}

@end
